package outoforder.leetcode;

import org.junit.Test;

/**
 * @author shhjiang_001
 * @create 2020-07-06 14:37
 */

// 最长公共子序列
public class Solution1143 {
    public int longestCommonSubsequence(String text1, String text2) {
        char[] chars1 = text1.toCharArray();
        char[] chars2 = text2.toCharArray();
        int m = chars1.length;
        int n = chars2.length;
        int[][] dp = new int[m + 1][n + 1];
        for (int i = 1; i <= m ; i++) {
            for (int j = 1; j <= n ; j++) {
                if (chars1[i-1] == chars2[j-1]){
                    dp[i][j] = dp[i-1][j-1]+1;

                }else {
                    dp[i][j] = Math.max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
        return dp[m][n];
    }
    @Test
    public void test(){
        System.out.println(longestCommonSubsequence("abc", "acb"));
    }
}
